using System;
using System.Data;
using Widgetsphere.Core.Exceptions;

namespace Widgetsphere.Core.DataAccess
{
	public partial class ReadOnlyDomainCollection : DomainCollectionBase
	{
		public ReadOnlyDomainCollection(string tableName)
		{
			base.TableName = tableName;
		}

		#region Methods

		public static void SetParameterValue(IDbCommand command, string paramName, object inValue)
		{
			try
			{
				var startDateParam = (IDbDataParameter)command.Parameters[paramName];
				if (startDateParam != null)
				{
					startDateParam.Value = inValue;
				}
				else
				{
					throw new WSException("Parameter: " + paramName + " is missing from stored procedure: " + command.CommandText);
				}
			}
			catch (Exception ex)
			{
				throw new WSException("Parameter: " + paramName + " is missing from stored procedure: " + command.CommandText, ex);
			}
		}

		public static IDbDataParameter GetOutputParameter(IDbCommand command, string paramName)
		{
			try
			{
				var outputParam = (IDbDataParameter)command.Parameters[paramName];
				if (outputParam == null)
				{
					throw new WSException("Parameter: " + paramName + " is missing from stored procedure: " + command.CommandText);
				}
				return outputParam;
			}
			catch (Exception ex)
			{
				throw new WSException("Parameter: " + paramName + " is missing from stored procedure: " + command.CommandText, ex);
			}
		}

		#endregion

	}
}